/*	====================================================
	This is the entry point of the kernel, 
	which is called from the bootloader.
	This entry point then puts out the calls to, 
	initialize the global constructors in cstd.cpp,
	and then to start our kernel..main.cpp
	====================================================
*/

extern void _cdecl main ();
extern void _cdecl InitializeConstructors();
extern void _cdecl Exit ();

void _cdecl kernel_entry () {

#ifdef ARCH_X86
	_asm {
		cli						// Clear interrupts
		mov ax, 10h				// Offset 0x10 in gdt for data selector
		mov ds, ax
		mov es, ax
		mov fs, ax
		mov gs, ax
		mov ss, ax				// Set up base stack
		mov esp, 0x90000
		mov ebp, esp			// Store current stack pointer
		push ebp
	}
#endif

	// Execute global constructors, specified in our cstd.cpp file
	InitializeConstructors();

	// Call kernel entry point (start our kernel..main.cpp)
	main ();

	// Cleanup all dynamic dtors
	Exit ();

#ifdef ARCH_X86
	_asm cli
#endif
	for (;;);
}
